package pokerbot;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import pokerbot.entities.Card;
import pokerbot.entities.Hand;
import pokerbot.entities.Player;
import pokerbot.entities.Table;

public class PokerGenerator {
    
    private static PokerGenerator instance = null;
    private static final Random random = new Random();
    private Table table = null;

    private PokerGenerator() {
    }
    
    public static PokerGenerator getInstance() {
        if (instance == null) {
            instance = new PokerGenerator();
        }
        return instance;
    }
    
    public Card generateCard() {
        return table.getDeck().testGetCardFromDeck();
    }
    
    public Hand generateHand() {
        return new Hand(generateCard(), generateCard());
    }
    
    public Player generatePlayer(int position) {
        Player player = new Player("player" + position, random.nextFloat() * 100, position);
        player.setHand(generateHand());
        return player;
    }
    
    public List<Player> generatePlayers(int playersCount) {
        List<Player> players = new ArrayList<>();
        for (int i = 0; i < playersCount; i++) {
            players.add(generatePlayer(i));
        }
        return players;
    } 
    
    public Table generaTable(int playersCount, int tableCardsNumber) {
        table = new Table();
        table.addPlayers(generatePlayers(playersCount));
        for (int i = 0; i < tableCardsNumber; i++) {
            table.addCard(generateCard());
        }
        return table;
    }
}
